#include <iostream>
#include <vector>

using namespace std;

int func(int B, int E, int t1, int t2, int t3)
{
    vector<vector<int>> dp(B + 1, vector<int>(E + 1, 101)); // dp[i][j]表示买i个包子和j个鸡蛋的最少时间
    for (int j = 0; j <= E; j += 20) dp[0][j] = t2 * (j / 20);
    for (int i = 0; i <= B; i += 32) dp[i][0] = t1 * (i / 32);
    dp[0][0] = t3;
    for (auto& vv : dp)
    {
        for (auto& v : vv)
        {
            cout << v << " ";
        }
        cout << endl;
    }
    for (int i = 16; i <= B; i++)
    {
        for (int j = 10; j <= E; j++)
        {
            if (i % 16 == 0 && j % 10 == 0)
            {
                // 比较三个时间
                int tm1 = 101, tm2 = 101, tm3 = 101;
                if (i >= 32)
                {
                    if (dp[i - 32][j] != 101)
                        tm1 = dp[i - 32][j] + t1;
                    cout << tm1 << endl;
                }
                if (j >= 20)
                {
                    if (dp[i][j - 20] != 101)
                        tm2 = dp[i][j - 20] + t2;
                    cout << tm2 << endl;
                }
                if (i >= 16 && j >= 10)
                {
                    if (dp[i - 16][j - 10] != 101)
                        tm3 = dp[i - 16][j - 10] + t3;
                    cout << tm3 << endl;
                }
                dp[i][j] = min(min(tm1, tm2), tm3);
                cout << endl;
            }
        }
    }
    for (auto& vv : dp)
    {
        for (auto& v : vv)
        {
            cout << v << " ";
        }
        cout << endl;
    }
    return dp[B][E] == 101 ? -1 : dp[B][E];
}

int main()
{
    int n = 0;
    cin >> n;
    while (n--)
    {
        int B = 0;
        int E = 0;
        int t1 = 0, t2 = 0, t3 = 0;
        cin >> B >> E >> t1 >> t2 >> t3;
        int ret = func(B, E, t1, t2, t3);
        cout << ret << endl;
    }
    return 0;
}